package 定长滑动窗口

// 入 多个哈希表
func maxSum(nums []int, m int, k int) (ans int64) {
	s := int64(0)
	cnt := map[int]int{}
	for i, num := range nums {
		s += int64(num)
		cnt[num]++
		//更
		left := i - k + 1
		if left < 0 {
			continue
		}
		if len(cnt) >= m {
			ans = max(ans, s)
		}
		out := nums[left]
		s -= int64(out)
		//出
		cnt[out]--
		if cnt[out] == 0 {
			delete(cnt, out)
		}

	}
	return
}
